﻿<?php @session_start();
require_once("include/header.php");

echo "<title>Nộp bài</title>";
if (!isset($_SESSION['user_id'])){
	redirect("index.php");
}
if (!isset($_GET['id'])){
	//redirect("index.php");
	$id=intval($_GET['pid']);
} else
	$id=intval($_GET['id']);
if (isset($_GET['pid'])) $pid=intval($_GET['pid']);
if (isset($_GET['cid'])) $cid=intval($_GET['cid']);
$cache_time=1; 



echo "<center>";
if($OJ_EDITE_AREA){

echo '<script language="Javascript" type="text/javascript" src="edit_area/edit_area_full.js"></script>';
?>
<script language="Javascript" type="text/javascript">
editAreaLoader.init({
	        id: "source"            
	        ,start_highlight: true 
	        ,allow_resize: "both"
	        ,allow_toggle: true
	        ,word_wrap: true
	        ,language: "en"
	        ,syntax: "pas"  
			,font_size: "11"
	        ,syntax_selection_allow: "c,cpp,pas"
			,toolbar: "search, go_to_line, fullscreen, |, undo, redo, |, select_font,syntax_selection,|, change_smooth_selection, highlight, reset_highlight, word_wrap, |, help"          
	});
</script>
<div class="body-wrap nobg">
	<div class="wrapper">
		
		
		<div class="main">
			<div class="col-a0">
<?php }
//,syntax_selection_allow: "basic,c,cpp,java,pas,perl,php,python,ruby"
echo '
<script src="include/checksource.js"></script>
<form action="submit.php"'.(isset($cid)?"?cid=".$cid:"");
echo ' method="post" >';

if (isset($id)){
	echo "<h3>Bài toán <span class=blue><b>$id</b></span></h3><br>";
	echo "<input type='hidden' value='$id' name='id'>";
}
else
{
	echo "<br>Bài toán: <span class='blue'><b>$pid</b></span> ";
	$sql="select * from problem where problem_id=$pid";
	$result=mysql_query($sql);
	$row=mysql_fetch_object($result);
	if ($row) echo $row->title;
	echo "<br><br>
	<input type='hidden' value='$cid' name='cid'>
	<input type='hidden' value='$pid' name='pid'>
	";
	
} 
 echo "Ngôn ngữ lập trình bạn chọn: <select id='language' name='language'>";
 $src="";
 $language=-1;
 if(isset($_GET['sid'])){
	$sid=intval($_GET['sid']);
	$sql="SELECT * FROM `solution` WHERE `solution_id`=".$sid;
	$result=mysql_query($sql);
	$row=mysql_fetch_object($result);
	if ($row && $row->user_id==$_SESSION['user_id']) 
	{
		$ok=true;
		$language = $row->language;
	}
	//if (($_SESSION['user_rights']{0}=="B")) $ok=true;
	mysql_free_result($result);
	if ($ok==true){
		$sql="SELECT `source` FROM `source_code` WHERE `solution_id`='".$sid."'";
		$result=mysql_query($sql);
		$row=mysql_fetch_object($result);
		$src=$row->source;
		mysql_free_result($result);
	}
	
 }
//if (!isset($langmask))
//{
	if(isset($_GET['langmask'])) {
		$langmask=$_GET['langmask'];
	} else {
		$langmask=$OJ_LANGMASK;
	}
//}

 $lang=(~((int)$langmask))&1023;
 $C_=($lang&1)>0;
 $CPP_=($lang&2)>0;
 $P_=($lang&4)>0;
 $J_=($lang&8)>0;
 $R_=($lang&16)>0;
 $B_=($lang&32)>0;
 $Y_=($lang&64)>0;
 $H_=($lang&128)>0;
 $L_=($lang&256)>0;
 $S_=($lang&512)>0;
if ($language<0) {
	if(isset($_COOKIE['lastlang'])) 
	{
		$lastlang=$_COOKIE['lastlang'];
	}
	else 
	{
		$lastlang=2;
	}
	$lastlang=2;
}
else
{
	$lastlang=$language;
}
 
 if($C_) echo"	    <option value=0 ".( $lastlang==0?"selected":"").">C</option>";
 if($CPP_) echo"	<option value=1 ".( $lastlang==1?"selected":"").">C++</option>";
 if($P_) echo"		<option value=2 ".( $lastlang==2?"selected":"").">Pascal</option>";
 //if($J_) echo"		<option value=3 ".( $lastlang==3?"selected":"").">Java</option>";
 //if($R_) echo"		<option value=4 ".( $lastlang==4?"selected":"").">Ruby</option>";
 //if($B_) echo"		<option value=5 ".( $lastlang==5?"selected":"").">Bash</option>";
 //if($Y_) echo"		<option value=6 ".( $lastlang==6?"selected":"").">Python</option>";
 //if($H_) echo"		<option value=7 ".( $lastlang==7?"selected":"").">PHP</option>";
 //if($L_) echo"		<option value=8 ".( $lastlang==8?"selected":"").">Perl</option>";
 //if($S_) echo"		<option value=9 ".( $lastlang==9?"selected":"").">C-Sharp</option>";
 echo "</select><br>";

?>

<textarea cols=100 rows=26 id="source" name="source"><?php echo $src?></textarea><br>
<input type="checkbox" name="sharecode" checked />Chia sẻ code<br/>
<input type=submit value="Nộp bài">
<!--<input type=reset value="Reset">-->
</form>
</center>
</div>
			
			<div class="clear"></div>
		</div>
	</div>
</div>
<?php require_once("include/footer.php")?>

